function fill(who,value,add){
	if(add==1){
		if(getid(who).value.indexOf(value)==-1){
			value = $('#'+who).val() + value;
			$('#'+who).val(value);
		}
		else{
			alert('已存在输入框中');
		}
	}else{
		$('#'+who).val(value);
	}
}

function fillcando(who){
	
	if (who == null){
		who = 'user';
	}

	var obj = getid(who + who + '1');
	if (obj.options[obj.selectedIndex].value!=''){
		var v1 = obj.options[obj.selectedIndex].value;
	}else{
		var v1 = obj.options[obj.selectedIndex].innerText;
	}
	
	if (v1 == '请选择'){
		v1='';
	}
	
	if (v1 != ''){
		
		var v = v1;

		var obj = getid(who + who + '2');
		if (obj.options[obj.selectedIndex].value!=''){
			var v2 = obj.options[obj.selectedIndex].value;
		}else{
			var v2 = obj.options[obj.selectedIndex].innerText;
		}
		
		if (v2 != '请选择'){
			v += ',' + v2;
		}

		fill('cando', v + '\r\n', 1);
	}
}

function add(){
	var s = confirm("真的要再次添加吗?");
	if(s){
		getid('id').value = '';
		getid('form').submit();
	}
}

function sortList(id, lv, is_onload, class){

	var obj;
	var path = '';
	//var id = Number(id.substring(2));

	//清除
	if (is_onload != 1){
		for ( i=Number(lv)+1; i<10; i++){
			$('#' + id + i).val('');
			$('#' + id + id + i).remove();
		}
	}
	
	//换值
	obj = getid(id + id + lv);
	if ( obj != null && is_onload != 1){
		if (obj.options[obj.selectedIndex].value!=''){
			var v = obj.options[obj.selectedIndex].value;
		}else{
			var v = obj.options[obj.selectedIndex].innerText;
		}
		if (v=='请选择'){
			$('#' + id + lv).val('');
		}
		else{
			$('#' + id + lv).val(v);
		}
	}
	
	//数目录
	for (i=0; i <= lv; i++){
		obj = getid(id + id + i);
		if (obj != null){
			path += obj.options[obj.selectedIndex].innerText;

			if (obj.options[obj.selectedIndex].value != obj.options[obj.selectedIndex].innerText){
				path += ',' + obj.options[obj.selectedIndex].value
			}

			path += '|';
		}
	}

	url =  "/index.php/sort/aj_sort";
	url += "/id/" + id;
	url += "/lv/" + lv;

	if ( $('#' + id + (lv+1)).val() != '' ){
		url += "/check/"+ $('#' + id + (lv+1)).val();
	}
	if (path != ''){
		url += "/dir/" + path;
	}
	if (class != ''){
		url += "/class/" + class;
	}
	url += "/rd/" + Math.random();
	
	//alert(url);
	//return false;
	
	$.get(url,function(txt){
		//alert(txt);
		if (txt!=''){
			$('#' + id + id + lv).after(txt);
			sortList ( id, lv+1, 1);
		}
	});

	if ( is_onload == 1 ){
		
	}
}

// FireFox innerText 支持
try{
        HTMLElement.prototype.__defineGetter__
        (
        "innerText",
        function ()
        {
            var anyString = "";
            var childS = this.childNodes;
            for(var i=0; i<childS.length; i++)
            {
                if(childS[i].nodeType==1)
                    anyString += childS[i].tagName=="BR" ? '"n' : childS[i].innerText;
                else if(childS[i].nodeType==3)
                    anyString += childS[i].nodeValue;
            }
            return anyString;
        }
    ); 
}
catch(e){}